	gadgets.util.registerOnLoadHandler(init);

	function init() {
	  loadFriends();
	}

	function loadFriends() {
	  var req = opensocial.newDataRequest();
	  req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER), 'viewer');
	  
	  var viewerFriends = opensocial.newIdSpec({ "userId" : "VIEWER", "groupId" : "FRIENDS" });
	  var opt_params = {};
	  req.add(req.newFetchPeopleRequest(viewerFriends, opt_params), 'viewerFriends');

	  req.send(onLoadFriends);
	}
	
	function onLoadFriends(data) {
	
	  var viewer = data.get('viewer').getData();
	  var viewerFriends = data.get('viewerFriends').getData();
	  
	  var id = viewer.getId();
	  var nickname = viewer.getDisplayName();
	  
	  var sendData = {};
	  sendData.uid = id;
	  sendData.uname = nickname;
	  
	  var friendArray = new Array();  
	  var i = 0;
	  
	  viewerFriends.each(function(person) {
		if (person.getId()) {
			friendArray.push({userId : person.getId(), userName : person.getDisplayName()});
		}
	  });
	  
	  sendData.friend = friendArray;
	  
	  alert(gadgets.json.stringify(sendData));
	  
	  //sendRequest(sendData);
	  
	}
	
	function sendRequest(data) {
		var params = {};
		params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
		params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
		params[gadgets.io.RequestParameters.POST_DATA] = gadgets.json.stringify(sendData);
		gadgets.io.makeRequest(
			"http://211.11.100.246/g/mainapp.jsp",
			getResponse,
			params
		);		
	}
	
	function getResponse(data) {
		
	}

	var flash_url = "http://211.11.100.246/h/CHorse.swf";
	
	function haveFlash() {
		var params = {
			width:"760",
			height:"590",
			wmode:"opaque",
			id:"flash_object"
		};
		gadgets.flash.embedFlash(
			flash_url,
			document.getElementById('flash'),
			6,
			params
		);
		gadgets.window.adjustHeight();
	};